package com.aaa.ssm.controller;

import com.aaa.ssm.entity.TreeNode;
import com.aaa.ssm.service.MenService;
import com.aaa.ssm.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
@RequestMapping("menu")
public class MenuController extends BaseController {
    @Resource
    private MenService menService;
    /**
     * 查询树形数据
     * @return
     */
    @GetMapping("queryTreeData")
    public Result queryTreeData1(){
        return success(menService.queryTreeDate());
    }
    /**
     * 根据用户编号查询  用户编号直接从登录成功的session中获取
     * @return
     */
    @GetMapping("queryTreeNodeByUserId")
    public Result queryTreeNodeByUserId() {
        return success(menService.queryTreeNodeByUserId());
    }
    /**
     * 添加
     * @param treeNode
     * @return
     */
    @PostMapping("add")  //地址栏中的请求，都是get请求，该请求无法在地址栏进行模拟  如果在地址栏模拟，会出现 HTTP状态 405 - 方法不允许
    public Result add(@RequestBody TreeNode treeNode) {//@RequestBody  把对象以json字符串的格式放入Request对象的Body中传递，get请求是没有body
        return success(menService.add(treeNode));
    }

    /**
     * 更新
     * @param treeNode
     * @return
     */
    @RequestMapping(value = "update",method = RequestMethod.POST)
    public Object update(@RequestBody  TreeNode treeNode) {
        return success(menService.update(treeNode));
    }

    /**
     * 根据编号删除对象
     * @param menuId
     * @return
     */
    @DeleteMapping("deleteById") //地址栏无法模拟  会报HTTP状态 405 - 方法不允许
    public Object deleteById(Integer menuId) {
        return success(menService.delete(menuId));
    }

}
